<table data-options="fit:true" id="fm_article"></table>
<script>
	$(function(){
		var datagrid;
		datagrid=$('#fm_article').datagrid({   
			url:"../json/BackFmArticleAction_SelectFmActicle",
    		loadMsg:'数据加载中...',
    		pagination:true,
		    fitColumns:true,
		    rownumbers:true,
		    striped:true,
		    pageNumber:1,
		    sortOrder:'asc',
		    remoteSort:false,//定义是否通过远程服务器对数据排序。
		    sortName:'fid',
    		columns:[[
    			{field:'fids',title:'',checkbox:true,width:100,align:'center'},      
		        {field:'fid',title:'编号',width:100,align:'center'},   
		        {field:'fname',title:'题目',width:100,align:'center'},   
		        {field:'ftype',title:'类型',width:100,align:'center'},
		        {field:'fauthor',title:'作者',width:100,align:'center'},
		        {field:'ftime',title:'收录时间',width:100,align:'center'},
		        {field:'fnumber',title:'播放次数',width:100,align:'center'}, 
		        {field:'fdownload',title:'下载次数',width:100,align:'center'},           
    		]],
    		toolbar: [{
				iconCls: 'icon-add',
				text:'添加',
				handler: function(){
					$('#addFm_article').dialog("open");
				}
			},'-',{
				text:'删除',
				iconCls: 'icon-remove',
				handler: function(){
					//获取选中的行
					var rows=datagrid.datagrid("getChecked");
					if(rows.length==0){
						$.messager.alert('错误提示','请选择您要删除的文章...','error');
					}else{
						//获取到行中的id
						var fid="";
						//如果有多个
						if(rows.length>1){
							for(var i=0;i<rows.length-1;i++){
								fid+=rows[i].fid+",";
								alert(rows[i].fid);
							}
							fid+=rows[i].fid;
						}else{
							fid=rows[0].fid;
						}
						$.ajax({
							url:"../json/BackFmArticleAction_DelFmArticle",
							dataType:'json',
							type:"post",
							data:{
								"fids":fid
							},
							success:function(data){
								if(data.result>0){
									$.messager.show({
										title:'成功提示',
										msg:'删除FM文章成功...',
										timeout:3000,
										showType:'slide'
									});
									datagrid.datagrid("reload");
								}else{
									$.messager.alert('错误提示','FM文章删除失败,请稍后重试...','error');
								}
							}
						});
					}
				}
			}] 
		}) 
	})
</script>
<div id="addFm_article" class="easyui-dialog" title="添加FM文章信息" style="width:800px;height:600px"
	data-options="iconCls:'icon-add',resizeble:true,modal:true,closed:true">
	<form action=""  id="addFm_article_form" style="padding:30px;"  enctype="multipart/form-data">
		<p><label>文章题目:</label><input type="text" id="fmarticle_name" name="fname"></p>
		<p><label>文章作者:</label><input type="text" id="fmarticle_author" name="fauthor"></p>
		<p><label>文章类型:</label>
			<select id="fmarticle_type" name="ftype">
				<option>请选择类型</option>
				<option value="烦躁">烦躁</option>
				<option value="孤独">孤独</option>
				<option value="悲伤">悲伤</option>
				<option value="快乐">快乐</option>
				<option value="迷忙">迷忙</option>
				<option value="感动">感动</option>
			</select>
		</p>
		<p><span>音频地址:</span><input type="file" id="fmarticle_aAudio" name="file"/></p>
		<span>文章图片:</span><input type="file" id="fmarticle_aaddr" name="file" multiple="multiple"  onchange="previewMultipleImage(this,'show_pic')"/>
		<div id="show_pic">		
		</div>
		<!-- 文章内容 -->
		<div>
			<script type="text/plain" id="editor" style="width:800px;height:300px"></script>
		</div>
		<a  class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="addFmArticle()">添加</a>
	</form>
</div>
<script>
	var ue=UE.getEditor('editor');
	
	function addFmArticle(){
		var fname=$("#fmarticle_name").val();
		var fauthor=$("#fmarticle_author").val();
		var ftype=$("#fmarticle_type").val();
		var fcontent=ue.getContent();
		console.info(fname+fauthor+ftype+fcontent);
		$.ajaxFileUpload({
			url:"../upload/BackFmArticleAction_addFmActicle",
			//fileElementId:['fmarticle_aaddr','fmarticle_aAudio'],
			fileElementId:'fmarticle_aaddr',
			secureuri:false,
			dataType:'json',
			type:"post",
			data:{
				fname:fname,
				fauthor:fauthor,
				ftype:ftype,
				fcontent:fcontent
			},
			success:function(data){
				if(data.obj!=null){
					$.ajaxFileUpload({
						url:"../upload/BackFmArticleAction_addFmActicleAudio",
						fileElementId:'fmarticle_aAudio',
						secureuri:false,
						dataType:'json',
						type:"post",
						data:{
							"fmArticle.fid":data.obj
						},
						success:function(data){
							if(data.obj!=null){
								$.messager.show({
									title:'成功提示',
									msg:'FM文章添加成功...',
									timeout:3000,
									showType:'slide'
								});
								$('#addFm_article').dialog("close");
								$("#addFm_article_form")[0].reset();
								$("#show_pic").html("");
								$('#fm_article').datagrid("reload");
								ue.setContent("");
							}else{
								$.messager.alert('错误提示','FM文章添加失败,请稍后重试...','error');
							}
						}
					});
				}else{
					$.messager.alert('错误提示','FM文章添加失败,请稍后重试...','error');
				}
			}
		});
	}
</script>
